# 查询员工信息
from db_client import *
from flask import request
import json
import sys
sys.path.append('..')


def search_staff():
    jobs = {
        '采购员': 0,
        '部门经理': 1,
        '总经理': 2,
    }
    staff = {}
    results = []
    staff_id = request.args.get('staff_id')
    results_tuple = mysql_client.search_staff(staff_id)
    for rt in results_tuple:
        results.append(list(rt))
    for result in results:
        pm = result[0].split(',')
        result[0] = pm
        t = {
            "id": result[0],
            "name": result[1],
            "superior_id": result[2],
            "job": jobs.get(result[3]),
            "department": result[4]
        }
        staff = t
    data = {
        "staff": staff
    }
    return json.dumps(data, ensure_ascii=False)
